package com.ease.framework.gef4p.commands {
   import com.ease.framework.gef.IEditor;
   import com.ease.framework.gef4p.editparts.AnnotationContainerEditPart;
   import com.ease.framework.gef4p.editparts.AnnotationEditPart;
   import com.ease.framework.gef4p.model.Annotation;
   import com.ease.framework.gef4p.model.IArtifactsContainer;
   import com.ease.framework.workbench.Workbench;
   import com.ease.framework.workbench.spi.impls.Command;

   public class RemoveAnnotationCommand extends Command {
      private var container:IArtifactsContainer;
      private var annotation:Annotation;

      private var annotationEditPart:AnnotationEditPart;

      public function RemoveAnnotationCommand(ann:Annotation) {
         super();
         annotation = ann;
         container = ann.container;
      }

      override public function execute():void {
         container.removeArtifact(annotation);
         if (annotationEditPart == null) {
            annotationEditPart = IEditor(Workbench.instance.currentEditor).getEditDomain().getEditPartByModel(annotation) as AnnotationEditPart;
         }
         annotationEditPart.remove();
         var processEditPart:AnnotationContainerEditPart = IEditor(Workbench.instance.currentEditor).getEditDomain().getEditPartByModel(container) as AnnotationContainerEditPart;
         processEditPart.removeAnnotationEditPart(annotationEditPart);
      }

      override public function undo():void {
         container.addArtifact(annotation);
         annotationEditPart.unremove();
         var processEditPart:AnnotationContainerEditPart = IEditor(Workbench.instance.currentEditor).getEditDomain().getEditPartByModel(container) as AnnotationContainerEditPart;
         processEditPart.addAnnotationEditPart(annotationEditPart);
      }
   }
}